﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class AdminPage_AddSchoolInfo : System.Web.UI.Page
{
    SqlConnection sqlcon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnString"].ToString());
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void LinkButton_addschool_Click(object sender, EventArgs e)
    {
        Panel_addschool.Visible = true;
    }
    protected void LinkButton_schoolmaintain_Click(object sender, EventArgs e)
    {

    }
    protected void Button_school_Click(object sender, EventArgs e)
    {

        
        sqlcon.Open();
        string schoolstr = TextBox_schoolname.Text;

                //字符分割，分割多个房间名称
        string[] arrStr = schoolstr.Split(',');

        bool insertOK = true;
        SqlFormat.beginTran(sqlcon);
        foreach (string schoolname in arrStr)
        {
           string insertSchoolSQL="insert SchoolTable (SchoolName,CountyId) values("+SqlFormat.ap(schoolname)+","+DropDownList_county.SelectedValue+");";
           //string insql = SqlFormat.insertTableNotAp("RoomTable", values);
           SqlDataAdapter sqldap = new SqlDataAdapter();
           sqldap.InsertCommand = new SqlCommand(insertSchoolSQL, sqlcon);
           try
           {
               if (sqldap.InsertCommand.ExecuteNonQuery() != 1)
               {
                   insertOK = false;
                   SqlFormat.rollback(sqlcon);
                   break;
               }
           }
           catch (System.Exception ex)
           {
              
               sqlcon.Close();
               Response.Write("<script language=javascript > alert('录入失败！');</script>");
               return ;
           }           
        }

        if (insertOK)
        {
            SqlFormat.commit(sqlcon);
            sqlcon.Close();
            Response.Write("<script language=javascript > alert('录入成功！');</script>");
        }
        else
        {
            sqlcon.Close();
            Response.Write("<script language=javascript > alert('录入失败！');</script>");
        }
    }
}